package com.cug.nageoffer.user.controller;

import com.cug.nageoffer.model.entity.UserChatRecord;
import com.cug.nageoffer.model.entity.UserStar;
import com.cug.nageoffer.model.vo.Result;
import com.cug.nageoffer.model.vo.ResultCodeEnum;
import com.cug.nageoffer.user.service.UserChatRecordService;
import com.cug.nageoffer.user.service.UserStarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "用户消息相关")
@RestController
@RequestMapping("/api/seeker/user/Message")
public class MessageController {

    @Resource
    private UserChatRecordService userChatRecordService;

    @Resource
    private UserStarService userStarService;

    /**
     * 用户发送消息
     */
    @Operation(summary = "用户发送消息")
    @PostMapping("/sendMessage")
    public Result<String> sendMessage(@RequestBody UserChatRecord requestParam){
        userChatRecordService.record(requestParam);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 用户接受消息
     */
    @Operation(summary = "用户接受消息")
    @PostMapping("/receiveMessage")
    public Result<String> receiveMessage(@RequestBody UserChatRecord requestParam){
        userChatRecordService.receive(requestParam);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询用户聊天记录
     */
    @Operation(summary = "查询用户聊天记录")
    @PostMapping("/query")
    public Result<List<UserChatRecord>> queryRecord(@RequestBody UserChatRecord requestParam){
        return userChatRecordService.queryRecord(requestParam);
    }

    /**
     * 批量删除聊天记录
     */
    @Operation(summary = "删除用户聊天记录")
    @PostMapping("/delete")
    public Result<String> deleteRecord(@RequestParam List<Integer> ids){
        return userChatRecordService.delete(ids);
    }

    /**
     * 记录用户收藏
     */
    @Operation(summary = "记录用户收藏")
    @PostMapping("/star")
    public Result<String> star(@RequestBody UserStar requestParam){
        return userStarService.star(requestParam);
    }

    /**
     * 取消用户收藏
     */
    @Operation(summary = "取消用户收藏")
    @PostMapping("/unStar")
    public Result<String> unStar(@RequestParam Integer id){
        return userStarService.unStar(id);
    }

    /**
     * 查询用户收藏信息
     */
    @Operation(summary = "查询用户收藏内容")
    @PostMapping("/queryStar")
    public Result<List<UserStar>> queryStar(@RequestParam Integer userId){
        return userStarService.queryStar(userId);
    }

    /**
     * 用户未读消息计数
     */
    @Operation(summary = "用户未读消息计数")
    @PostMapping("/unreadCount")
    public Result<Long> unreadCount(@RequestBody UserChatRecord requestParam){
        return userChatRecordService.unreadCount(requestParam);
    }
}
